import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'
import Layout from '@/layout/index.vue'
// import { component } from 'vue/types/umd'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login')
  },
  {
    path: '/',
    name: 'Layout',
    component: Layout,
    // 配置路由重定向
    redirect: '/dashboard',
    children: [
      {
        path: '/dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard.vue'),
        meta: {
          title: '首页'
        }
      }
    ]
  },
  {
    path: '/system',
    name: 'System',
    component: Layout,
    // redirect: '/404',
    children: [
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/system/user/index.vue'),
        meta: {
          title: '用户管理'
        }
      },
      {
        path: 'role',
        name: 'Role',
        component: () => import('@/views/system/role/index.vue'),
        meta: {
          title: '角色管理'
        }
      },
      {
        path: 'menu',
        name: 'Menu',
        component: () => import('@/views/system/menu/index.vue'),
        meta: {
          title: '菜单管理'
        }
      }
    ]
  },
  {
    // 配置匹配不到相同路径的 404 路由 必须放在最后
    path: '*',
    redirect: '/404'
  },
  {
    path: '/404', // 前面路由匹配不成功才执行
    name: '404',
    component: () => import('@/views/error/index.vue')
  }
]

const router = new VueRouter({
  routes
})

export default router
